/*
 * TestConnexion.java
 *
 * Created on 20 avril 2009, 18:04
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.sinas;

import com.sun.spot.io.j2me.radiogram.*;

import com.sun.spot.util.IEEEAddress;
import java.io.IOException;
import javax.microedition.io.*;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.sun.spot.util.Utils;


/**
 *
 * @author Nicolas
 */
public class TestConnexion  extends Thread {
    
    
    private static final int HOST_PORT_TEST = 68; 
    
    private static final int SAMPLE_PERIOD = 1 * 100;  // in milliseconds
    
    /** Creates a new instance of TestConnexion */
    public void run() {
        
        RadiogramConnection testCon = null;
        Datagram testdg = null;
        
        try {
            // Open up a broadcast connection to the host port
            // where the 'on Desktop' portion of this demo is listening
            testCon = (RadiogramConnection) Connector.open("radiogram://broadcast:" + HOST_PORT_TEST);
            testdg = testCon.newDatagram(50);  // only sending 12 bytes of data
        } catch (Exception e) {
            System.err.println("Caught " + e + " in connection initialization.");
        }
        
        while(true)
        {
            
            try {
                testdg.reset();
                testdg.writeLong(1);
                testCon.send(testdg);
            } catch (IOException ex) {
                
            }
            
            Utils.sleep(SAMPLE_PERIOD);
        }

    }
    
}
